define([
    "angularModule",
    "draggabilly",
    "jquery",
    "angular"
], function(angularModule, draggabilly) {
	//
	let bimView = function() {
		console.log("bimView初始化");
	};


	Object.assign(bimView.prototype, {
        // demo : function() {},
        init: function(event) {

            // });

            // 初始化；插入到传入的ID节点中
            // bimView.prototype.init = function(event) {
            if (!event) {
                return;
            }
            // 整体外壳
            let BIMViewAPIcontent = $("<div class='BIMView-API-content'></div>");
            BIMViewAPIcontent.attr({
                "onselectstart": "return false",
                "ng-app": "bimApiAgular",
                "ng-controller": "bimApiCtrl"
            });
            $("#" + event).append(BIMViewAPIcontent);
            $("#" + event).css({
                "display": "block",
                "width": "100%",
                "height": "100%",
                "overflow": "hidden"
            });
            $("head").append("<link rel='stylesheet' type='text/css' href='Module/demo181026/css/bimView-api-2.css' />");
            // $("head").append("<link rel='stylesheet' type='text/css' " +
            //     "href='http://192.168.2.145/BIMAPI/Module/demo181026/css/bimView-api-2.css' />");
            // $("head").append("<link rel='stylesheet' type='text/css' " +
            //     "href='http://192.168.2.204:1001/Module/demo181026/css/bimView-api-2.css' />");

            // this.loadAngular();

            // 侧栏
            let BIMViewAPIslider = $("<div class='BIMView-API-slider'></div>");
            BIMViewAPIcontent.append(BIMViewAPIslider);
            BIMViewAPIslider.append("<div bim-api-slider></div>");

            // 底部按钮
            let BIMViewAPIbottom = $("<div class='BIMView-API-bottom'></div>");
            BIMViewAPIcontent.append(BIMViewAPIbottom);
            BIMViewAPIbottom.append("<div bim-api-bottom></div>");

            // 拖动模块
            let BIMViewAPIdrag = $("<div class='BIMView-API-drag'></div>");
            let dragDemo = $("<!-- 2、属性 -->" +
                "<div bim-api-model-property></div>" +
                "<!-- 3、模型结构 -->" +
                "<div bim-api-model-structure></div>" +
                "<!-- 4、视角书签 （和6、标注；公用一套CSS）-->" +
                "<div bim-api-model-eyesmark></div>" +
                "<!-- 5、搜索 -->" +
                "<div bim-api-model-search></div>" +
                "<!-- 6、标注 -->" +
                "<div bim-api-model-sign></div>" +
                "<!-- 7、剖切 -->" +
                "<div bim-api-model-section></div>" +
                "<!-- 9、定位 -->" +
                "<div bim-api-model-location></div>" +
                "<!-- 11、分解 -->" +
                "<div bim-api-model-resolve></div>" +
                "<!-- 12、设置 -->" +
                "<div bim-api-model-setting></div>");
            BIMViewAPIcontent.append(BIMViewAPIdrag);
            BIMViewAPIdrag.append(dragDemo);

            // 0040：canvas3D画布模型模块**************************************************************************************
            let BIMViewAPIcanvas3d = $("<div class='BIMView-API-canvas3d' id='Canvas'></div>");
            BIMViewAPIcontent.append(BIMViewAPIcanvas3d);

            // 手动启动angular
            angular.bootstrap(document.querySelector(".BIMView-API-content"), ['bimApiAgular']);

            // 拖动方法初始化（纯js调用三种方法+可查看方法的地址）
            // http://www.htmleaf.com/jQuery/Layout-Interface/201509142570.html
            // 第一种方法
            /*var elem = document.querySelector('.draggable');
            var draggie = new Draggabilly( elem, {
              // options...
            });*/
            // 第二种方法
            /*let dragModule = new draggabilly('.draggable', {
                containment: true
            });*/
            // 第三种方法;get all draggie elements
            let draggableElems = document.querySelectorAll('.draggable');
            // array of Draggabillies
            let draggies = [];
            // init Draggabillies
            for (let i = 0, len = draggableElems.length; i < len; i++) {
                let draggableElem = draggableElems[i];
                let draggie = new draggabilly(draggableElem, {
                    containment: true
                });
                draggies.push(draggie);
            }
            // 一些小组件的方法事件（不方便用css表示或者不适合其他）
            // 下拉组件dropdown系列相关
            $(".BIMView-API-content .BIMView-API-drag .dropdown .dropbtn").on("click", function() {
                //$(".BIMView-API-content .BIMView-API-drag .dropdown .dropdown-content").css("display", "block");
                $(this).parent(".dropdown").find(".dropdown-content").css("display", "block");
            });
            $(".BIMView-API-content .BIMView-API-drag .dropdown, .BIMView-API-content .BIMView-API-drag .dropdown .dropdown-content").on("mouseleave", function() {
                //$(".BIMView-API-content .BIMView-API-drag .dropdown .dropdown-content").css("display", "none");
                $(this).find(".dropdown-content").css("display", "none");
                $(this).parent(".dropdown").find(".dropdown-content").css("display", "none");
            });
            $(".BIMView-API-content .BIMView-API-drag .dropdown .dropdown-content a").on("click", function() {
                //$(".BIMView-API-content .BIMView-API-drag .dropdown .dropdown-content").css("display", "none");
                $(this).parent(".dropdown-content").css("display", "none");
            });
            // };
        }
    });

	return bimView;
});